package com.thon.service.system.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;






import com.thon.dao.system.DicDao;
import com.thon.dao.system.DicDataDao;
import com.thon.dao.util.Page;
import com.thon.entity.system.Dic;
import com.thon.entity.system.DicData;
import com.thon.service.system.DicService;


@Service
@Transactional
public class DicServiceImpl implements DicService{

	@Autowired
	private DicDao sysDicDao;	
	
	@Autowired
	private DicDataDao sysDicDataDao;	


	@Override
	public Dic read(Integer id) {		
		
	    return sysDicDao.get(id);
	}

	@Override
	public String create(Dic Dic) {
		String msg = "success";		
		sysDicDao.save(Dic);
		return msg;
	}

	@Override
	public String delete(Integer id) {
		String msg = "success";		
		sysDicDao.delete(id);
		return msg;
	}

	@Override
	public String update(Dic Dic) {
		String msg = "success";		
		sysDicDao.update(Dic);
		return msg;
	}

	@Override
	public List<Dic> readList() {
	
			return sysDicDao.readList();
	
	}

	@Override
	public Page<Dic> readListPage(Integer pageNo, Integer pageSize) {
		Page<Dic> page = new Page<Dic>();
		page.setPageNo(pageNo);
		page.setPageSize(pageSize);		
		return sysDicDao.readListPage(page);
	}
	
	@Override
	public Page<DicData> selectDicDataListPage(String by, Object val,
			Integer pageNo, Integer pageSize) {
		Page<DicData> page = new Page<DicData>();
		page.setPageNo(pageNo);
		page.setPageSize(pageSize);	
		page.desc("sort");
		return sysDicDataDao.readListPage(page,by,val);
	}

	@Override
	public DicData readDicData(Integer id) {
		 return sysDicDataDao.get(id);
	}

	@Override
	public List<DicData> readDicDataList() {
		return sysDicDataDao.readList();
	}

	@Override
	public Page<DicData> readDicDataListPage(Integer pageNo,
			Integer pageSize) {
		Page<DicData> page = new Page<DicData>();
		page.setPageNo(pageNo);
		page.setPageSize(pageSize);
		page.desc("sort");
		return sysDicDataDao.readListPage(page);
	}

	@Override
	public String createDicData(DicData Dic) {
		String msg = "success";		
		sysDicDataDao.save(Dic);
		return msg;
	}

	@Override
	public String deleteDicData(Integer id) {
		String msg = "success";		
		sysDicDataDao.delete(id);
		return msg;
	}

	@Override
	public String updateDicData(DicData Dic) {
		String msg = "success";		
		sysDicDataDao.update(Dic);
		return msg;
	}

	@Override
	public List<DicData> getDicData(String by, Object val) {
		Dic Dic = sysDicDao.getOne(by,val);
		if(Dic==null)
			return null;		
		return sysDicDataDao.readList("dic.id", Dic.getId());
	}

	@Override
	public boolean checkDicUnique(String by, Object val) {
		if(null==sysDicDao.getOne(by, val))
			return true;
		else
			return false;
	}

	@Override
	public boolean checkDicDataUnique(String by, Object val) {
		if(null==sysDicDataDao.getOne(by, val))
			return true;
		else
			return false;
	}




	


}